package com.rabbiter.ordering.controller;

import com.rabbiter.ordering.entity.CategorySalesDTO;
import com.rabbiter.ordering.entity.FullReportDTO;
import com.rabbiter.ordering.entity.MonthlySalesDTO;
import com.rabbiter.ordering.entity.Result;
import com.rabbiter.ordering.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/reports")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/by-category")
    public Result getSalesByCategory(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {



        List<CategorySalesDTO> data = reportService.getSalesByCategory(startDate, endDate);
        return Result.success(data);
    }

    @GetMapping("/by-month")
    public Result getSalesByMonth(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {


        List<MonthlySalesDTO> data = reportService.getSalesByMonth(startDate, endDate);
        return Result.success(data);
    }

    @GetMapping("/full-report")
    public Result getFullReport(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam(required = false) String status) {



        List<FullReportDTO> data = reportService.getFullReport(startDate, endDate, status);
        return Result.success(data);
    }
}